﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Globalization;
using CCF20Model;
using WiseLink.RDS.Resource;

namespace CCF20Module
{
    [ValueConversion(typeof(Device), typeof(string))]
    public class MaintenanceStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Device device = value as Device;
            if ( device != null && device.Customer != null && device.Vehicle != null && device.DeviceStatus == DeviceStatus.Sold &&  
                 device.Customer.Vehicles.FirstOrDefault() != null)
            {
                return string.Format(Message.MaintenanceStringConverter,
                        device.Customer.Name,
                        device.Vehicle.VehicleLicense,
                        device.IDCSimNumber,
                        device.Vehicle.CurrentMileage,
                        device.Vehicle.VehicleType.Manufacture,
                        device.Vehicle.VehicleType.Model,
                        device.Vehicle.VehicleType.EngineType,
                        device.Vehicle.VehicleType.ModelYear);
            }
            else
            {
                return null;
            }
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
    
}
